<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link href="../css/style.css" rel="stylesheet" />
		<style>
			.area {
				margin: 20px auto 0px auto;
			}
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			.mui-input-group label {
				width: 22%;
			}
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 78%;
			}
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}
			.mui-content-padded {
				margin-top: 25px;
			}
			.mui-btn {
				padding: 10px;
			}
			
		</style>
	</head>

	<body ng-app="mainApp" ng-controller="oldTjCtrl" >
		<header class="mui-bar mui-bar-nav mui-bar-detail">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">旧物提交</h1>
		</header>
		<div class="mui-content reg_con ">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>名称</label>
					<input  id='title' name='title' ng-model="old.title"  type="text" class="mui-input-clear mui-input" placeholder="请输入名称">
				</div>
				<div class="mui-input-row">
					<label>重量</label>
					<input id='perWeight' name='perWeight' type="number" ng-model="old.perWeight"  class="mui-input-clear mui-input" placeholder="请输入重量">
				</div>
				<div class="mui-input-row">
					<label>类型</label>
					<select class="mui-h5" style="margin: auto;" ng-model="old.type">
						<option value="">--请选择类型--</option>
						<option ng-repeat=" gt in typeList" value="{{gt.id}}">{{gt.typeName}}</option>
					</select>
				</div>
				<div class="mui-input-row">
					<label>描述</label>
					<input id='des' name='des' type="text" ng-model="old.des" class="mui-input-clear mui-input" placeholder="请输入旧物描述">
				</div>
				
				<div class="mui-input-row feedback" style="height: 130px;">
					<label>图片</label>
					<input id='yyzz' name='yyzz' ng-model="user.yyzz" type="text" class="mui-input-clear mui-input" placeholder="请上传图片" readonly="true">
					<div id='image-list' class="row image-list" ></div>
				</div>
				
			</form>
			<div class="mui-content-padded">
				<button  class="mui-btn mui-btn-block mui-btn-primary reg" ng-click="submitOld()">提交</button>
			</div>
			<div class="mui-content-padded">
				<p>旧物提交后请耐心等待管理员审核。</p>
			</div>
		</div>
		<!--common---start-->
		<script src="../js/angular/angular.min.js"></script>
		<script src="../js/angular/angular-resource.js"></script>
		<script src="../js/angular/common.js"></script>
		<!--common---end-->
		<script src="../js/mui.min.js"></script>
		<script src="../js/common.js"></script>
		<script src="../js/service/oldGoodsService.js"></script>
		<script src="../js/feedback-page.js" type="text/javascript" charset="utf-8"></script>
		<script>
				mainApp.controller('oldTjCtrl', function($scope, $http,oldGoodsService) {
					(function($, doc) {
					$.init();
					$.plusReady(function() {
						
						var sucesstj=function(data){
							mui.alert("提交成功");
							mui.openWindow({//这里跳转到我的旧物列表页
								url:'myOld.html',
								id:'myOld'+new Date().getMilliseconds(),
								preload: true,
								show: {
									aniShow: 'pop-in'
								},
								waiting: {
									autoShow: false
								}
							});
						}
						var error=function(data){
							mui.alert("操作失败");
						}
						var sucess_d=function(data){
							$scope.typeList=data.data;
						}
						var getGoodType=function(){
							oldGoodsService.getGoodType("2",sucess_d,error)
						}
						getGoodType();
						$scope.submitOld=function(){
							 //上传附件
		                    var formData = new FormData();
		                    if(document.querySelector('input[type="file"]').files[0]!=null){
		                        formData.append("file",document.querySelector('input[type="file"]').files[0]);
		                    }else{
		                        mui.alert("请选择文件");
		                    }
							uploadFile(formData);
						};
						var uploadFile=function (formData) {
		                 	$http({
	                            method:'POST',
	                            url:baseUrl+"/dapi/upload/old",
	                            data: formData,
	                            headers: {'Content-Type':undefined},
	                            transformRequest: angular.identity
	                        }).success(function(data){
	                            $scope.pic_path=data.data;
	                            if ($scope.old.title==undefined||$scope.old.title=="") {
								plus.nativeUI.toast('请输入名称');
								return;
								}
								if ($scope.old.perWeight==undefined||$scope.old.perWeight=="") {
								plus.nativeUI.toast('请输入重量');
								return;
								}
								if ($scope.old.type==undefined||$scope.old.type=="") {
								plus.nativeUI.toast('请选择类型');
								return;
								}
								if ($scope.pic_path==undefined||$scope.pic_path=="") {
								plus.nativeUI.toast('请先上传图片');
								return;
								}else{
									$scope.old.iconUrl=$scope.pic_path;
								}
								//执行添加的方法
								oldGoodsService.addOld($scope.old,sucesstj,error);
	                        });
		                };
					});
				}(mui, document));
				//上传图片
		               
				
				});
			
		</script>
	</body>

</html>